package main

import (
	"context"
	"github.com/micro/go-micro"
	"log"
	"microstudent/proto/student"
	"microstudent/proto/teacher"
)

func main() {
	srv := micro.NewService(
		micro.Name("dh.com.microStudent.client"),
	)

	srv.Init()

	ss := student.NewStudentService("dh.com.microStudent", srv.Client())
	_, err := ss.Add(context.Background(), &student.AddRequest{Student: &student.Student{Name: "zhang san", Age: 21}})
	if err != nil {
		log.Fatalln(err)
	}

	resp, err := ss.FindAll(context.Background(), &student.FindAllRequest{})
	if err != nil {
		log.Fatalln(err)
	}
	log.Println(resp.Students)

	log.Println("=================")

	ts := teacher.NewTeacherService("dh.com.microStudent", srv.Client())
	_, err = ts.Add(context.Background(), &teacher.AddRequest{Teacher: &teacher.Teacher{Name: "li li"}})
	if err != nil {
		log.Fatalln(err)
	}

	respT, err := ts.FindAll(context.Background(), &teacher.FindAllRequest{})
	if err != nil {
		log.Fatalln(err)
	}
	log.Println(respT.Teachers)
}
